﻿using System;
using System.Diagnostics;
using System.Windows.Forms;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using YJKCodeBase.WinForm;
using YJKView;
using SectionSignAndFilled.StairsRoomPlanSign.ControlLayer;
using SectionSignAndFilled.StairsRoomSection.Manager;

namespace SectionSignAndFilled.StairsRoomSection
{
	[Transaction(TransactionMode.Manual)]
	internal class CmdSectionStairs : IExternalCommand
	{
		public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
		{
			int num = Convert.ToInt32(commandData.Application.Application.VersionNumber);
			if (2015 >= num)
			{
				MessageBox.Show("此功能只在Revit2016及其以上版本可用", "盈建科提示");
				return Autodesk.Revit.UI.Result.Succeeded;
			}
			UIApplication application = commandData.Application;
			CmdViewType types = (CmdViewType)75;
			if (SwitchView.SetUsableView(types, commandData) != Autodesk.Revit.UI.Result.Succeeded)
			{
				return Autodesk.Revit.UI.Result.Failed;
			}
			if (CmdSectionStairs._hWndRevit == null)
			{
				Process currentProcess = Process.GetCurrentProcess();
				IntPtr mainWindowHandle = currentProcess.MainWindowHandle;
				CmdSectionStairs._hWndRevit = new WindowHandle(mainWindowHandle);
			}
			UIDocument activeUIDocument = commandData.Application.ActiveUIDocument;
			try
			{
				Reference reference = activeUIDocument.Selection.PickObject(Autodesk.Revit.UI.Selection.ObjectType.Element, new DetailViewBlockSelectFilter(), "选择一个视图");
				SectionStairsRoomManager sectionStairsRoomManager = new SectionStairsRoomManager(application, CmdSectionStairs._hWndRevit, reference.ElementId, 1, commandData);
				sectionStairsRoomManager.Run();
			}
			catch (Exception ex)
			{
                string sss = ex.Message;
				return Autodesk.Revit.UI.Result.Failed;
			}
			return Autodesk.Revit.UI.Result.Succeeded;
		}

		public static WindowHandle _hWndRevit;
	}
}
